package com.jeasonzhao.report.model;

import com.jeasonzhao.commons.utils.Algorithms;

public class ReportColumnValueCollection extends java.util.Vector<ReportColumnValue>
{
    private static final long serialVersionUID = 1L;
    public ReportColumnValueCollection()
    {

    }

    public ReportColumnValueCollection(Iterable<ReportColumnValue> colls)
    {
        if(null == colls)
        {
            return;
        }
        for(java.util.Iterator<ReportColumnValue> it = colls.iterator();it.hasNext();)
        {
            add(it.next());
        }
    }

    public int hashCode()
    {
        StringBuffer buf = new StringBuffer();
        for(int n = 0;n < this.size();n++)
        {
            buf.append(Algorithms.padRight("" + (null == this.get(n) ? 0 : this.get(n).hashCode()),20,'*'));
        }
        return buf.toString().hashCode();
    }

    public ReportColumnValueCollection left(int nBeginIndexNotInclude)
    {
        ReportColumnValueCollection ret = new ReportColumnValueCollection();
        for(int x = 0;x < nBeginIndexNotInclude && x < this.size();x++)
        {
            ret.add(new ReportColumnValue(this.get(x)));
        }
        return ret;
    }

    public ReportColumnValueCollection right(int nBeginIndexNotInclude)
    {
        ReportColumnValueCollection ret = new ReportColumnValueCollection();
        for(int x = nBeginIndexNotInclude + 1;x < this.size();x++)
        {
            ret.add(new ReportColumnValue(this.get(x)));
        }
        return ret;
    }

    public ReportColumnValueCollection rightTotal(int nBeginIndexNotInclude)
    {
        ReportColumnValueCollection ret = new ReportColumnValueCollection();
        for(int x = nBeginIndexNotInclude + 1;x < this.size();x++)
        {
            if(this.get(x).isMeasure())
            {
                ret.add(this.get(x));
            }
            else
            {
                ret.add(ReportColumnValue.totalValue(this.get(x).getReportColumn()));
            }
        }
        return ret;
    }

    public String toString()
    {
        StringBuffer buf = new StringBuffer();
        for(int n = 0;n < this.size();n++)
        {
            buf.append("  " + this.get(n).toString());
        }
        return buf.toString();
    }

    public boolean equals(Object obj)
    {
        return Algorithms.areEquals(this,obj);
    }

    public boolean isNormal()
    {
        for(int n = 0;n < this.size();n++)
        {
            if(null != this.get(n) && this.get(n).isTotalCell())
            {
                return false;
            }
        }
        return true;
    }

    public void addCollection(Iterable<ReportColumnValue> colls)
    {
        if(null == colls)
        {
            return;
        }
        for(java.util.Iterator<ReportColumnValue> it = colls.iterator();it.hasNext();)
        {
            add(it.next());
        }
    }
}
